<script setup>
import { ref, onMounted } from 'vue'
import { useUserStore } from '@/stores/userStore'
import { getExpertDetailAPI, updateExpertInfoAPI } from '@/apis/expert'

const userStore = useUserStore()

const expert = ref({})

const updateExpertInfo = async () => {
    if (expert.value.realName === '' || expert.value.phone === '' 
        || expert.value.profession === '' || expert.value.position === '') {
        ElMessage({ type: 'warning', message: '请完整填写信息' })
        return
    }
    const res = await updateExpertInfoAPI({ ...expert.value, id: expert.value.id })
    if (res.code === 2000) {
        ElMessage({ type: 'success', message: '修改成功' })
    }
}

onMounted(async () => {
    const res = await getExpertDetailAPI(userStore.userInfo?.id)
    if (res.code === 2000) {
        expert.value = res.data
    }
})
</script>

<template>
<div class="expertInfo-page">
    <div class="page-title">专家信息</div>
    <div class="page-body">
        <div>
            <div class="label">真实姓名：</div>
            <div class="ipt"><input type="text" v-model="expert.realName"></div>
        </div>
        <div>
            <div class="label">手机号：</div>
            <div class="ipt"><input type="text" v-model="expert.phone"></div>
        </div>
        <div>
            <div class="label">从事专业：</div>
            <div class="ipt"><input type="text" v-model="expert.profession"></div>
        </div>
        <div>
            <div class="label">职位：</div>
            <div class="ipt"><input type="text" v-model="expert.position"></div>
        </div>
        <div>
            <div class="label">所属单位：</div>
            <div class="ipt"><input type="text" v-model="expert.belong"></div>
        </div>
        <div>
            <div class="label"></div>
            <a href="javascript:;" class="btn" @click="updateExpertInfo">修 改</a>
        </div>
    </div>
</div>
</template>

<style scoped lang='scss'>
.expertInfo-page {
    width: 100%;
    height: 100%;
    padding: 20px 40px;
    background-color: #fff;
}

.page-title {
    font-size: 21px;
    padding: 15px 0;
    border-bottom: 1px solid #e8e8e8;
}

.page-body {
    margin-top: 40px;

    >div {
        display: flex;
        align-items: center;
        margin-bottom: 30px;

        &:last-child {
            margin-bottom: 0;
        }
    }

    .label {
        width: 100px;
        color: #666;
        font-weight: bold;
    }

    .ipt {
        width: 300px;
        height: 35px;
        border: 1.5px solid #d8d8d8;
        border-radius: 5px;

        input {
            width: 100%;
            height: 100%;
            font-size: 16px;
            padding: 0 10px;
            border-radius: 5px;
        }
    }

    .btn {
        display: block;
        width: 100px;
        height: 35px;
        line-height: 35px;
        border-radius: 4px;
        font-size: 14px;
        color: #fff;
        background-color: #39bf3e;
        text-align: center;
    }
}
</style>
